package com.liu.manager.controller;

import com.alibaba.fastjson2.JSON;
import com.alibaba.fastjson2.JSONWriter;
import com.liu.manager.bean.ResponseResult;
import com.liu.manager.entity.RolerAndPermission;
import com.liu.manager.entity.SysRolerGroup;
import com.liu.manager.service.SysRolerGroupService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

@Slf4j
@RestController
@RequestMapping(value = "/sysrolergroup")
public class SysRolerGroupController {

    @Resource
    SysRolerGroupService service;

    @PostMapping(value = "/addRolerGroup",produces = {"application/json;charset=utf-8"})
    public String addRolerGroup(@RequestBody SysRolerGroup sysRolerGroup){
        ResponseResult responseResult = service.insertRolerGroup(sysRolerGroup);
        log.info(JSON.toJSONString(responseResult, JSONWriter.Feature.FieldBased,JSONWriter.Feature.WriteNulls));
        return JSON.toJSONString(responseResult, JSONWriter.Feature.FieldBased,JSONWriter.Feature.WriteNulls);
    }

    @PostMapping(value = "/removeRolerGroup",produces = {"application/json;charset=utf-8"})
    public String removeRolerGroup(long id){
        ResponseResult responseResult = service.deleteRolerGroup(id);
        return JSON.toJSONString(responseResult, JSONWriter.Feature.FieldBased,JSONWriter.Feature.WriteNulls);
    }

    @PostMapping(value = "/updateRolerGroup",produces = {"application/json;charset=utf-8"})
    public String updateRolerGroup(@RequestBody SysRolerGroup sysRolerGroup){
        ResponseResult responseResult = service.updateRolerGroup(sysRolerGroup);
        return JSON.toJSONString(responseResult, JSONWriter.Feature.FieldBased,JSONWriter.Feature.WriteNulls);
    }
    @GetMapping(value = "/findById",produces = {"application/json;charset=utf-8"})
    public String findById(long id){
        ResponseResult responseResult = service.findById(id);
        return JSON.toJSONString(responseResult, JSONWriter.Feature.FieldBased,JSONWriter.Feature.WriteNulls);
    }

    @GetMapping(value = "/findAll",produces = {"application/json;charset=utf-8"})
    public String findAll(){
        ResponseResult responseResult = service.findAll();
        return JSON.toJSONString(responseResult, JSONWriter.Feature.FieldBased,JSONWriter.Feature.WriteNulls);
    }
}
